﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;
using Kooboo.HtmlFunc.Function;

namespace Kooboo.HtmlFunc.Analysis.Testers
{
    public class AttributeTester : IFuncTester
    {
        public AttributeTester(string name, string value)
        {
            this.NameTester = new StringTester(name);
            this.ValueTester = new StringTester(value);
        }

        public IFuncTester NameTester
        {
            get;
            private set;
        }

        public IFuncTester ValueTester
        {
            get;
            private set;
        }

        #region IFuncTester Members

        public bool IsMatch(object real)
        {
            var attribute = real as HtmlAttribute;
            if (attribute == null)
            {
                throw new ArgumentException();
            }

            if (this.NameTester.IsMatch(attribute.Name) &&
                this.ValueTester.IsMatch(attribute.Value))
            {
                return true;
            }

            return false;
        }

        #endregion
    }
}
